package com.repast.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.repast.dao.CallWaitressMapper;
import com.repast.dao.DeskTimeMapper;
import com.repast.pojo.CallWaitress;
import com.repast.pojo.DeskTime;

@Service
public class TaskServiceImpl{

	@Autowired
	private DeskTimeMapper deskTimeMapper;
	
	@Autowired
	private CallWaitressMapper callMapper;

	private static final Logger logger = LoggerFactory.getLogger(TaskServiceImpl.class);

	public void deleteDeskTime() throws Exception {
		// 每天0点删除预约时间为0点之前的预约时间表
		List<DeskTime> list = deskTimeMapper.selectDeskTimeList();
		if (list.size() != 0) {
			for (DeskTime deskTime : list) {
				String deskTimeStartTime = deskTime.getDeskTimeStartTime();
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				Date start = sdf.parse(deskTimeStartTime);
				Date date = new Date();
				if (date.after(start)) {
					int resultDelete = deskTimeMapper.deleteByPrimaryKey(deskTime.getDeskTimeId());
					if (resultDelete == 0) {
						logger.debug("删除过时预约时间失败");
						return;
					}
					logger.debug("删除过时预约时间成功");
				}
			}
		}
	}
	
	public void deleteCallWaitress(){
		List<CallWaitress> list = callMapper.selectCallList();
		if(list.size()!=0){
			for (CallWaitress callWaitress : list) {
				if(null!=callWaitress){
					int deleteCall = callMapper.deleteByPrimaryKey(callWaitress.getCallId());
					if(deleteCall!=0){
						logger.debug("删除呼叫服务员成功");
					}
					if(deleteCall==0){
						logger.debug("删除呼叫服务员失败");
					}
				}
			}
		}
	}
}
